<?php
session_start();
if(! isset($_SESSION['id'])) {
    header('Location:index.html');
}
?>


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>发消息</title>
    <link href="css/bootstrap.min.css" type="text/css" rel="stylesheet">
    <script src="js/jquery.min.js"></script>
    <script src="js/bootstrap.min.js"></script>
    <style>
        .div{
            position: relative;
            text-align: center;
            padding-left: 500px;
        }
        .font{
            font-size: 16px;
            font-weight: bold;;
        }
        form{
            font-weight:bold;
        }
    </style>
</head>
<body style="text-align: center">
<?php include ('menu.php');
//1. 链接数据库
header("content-type:text/html;charset=utf8");
include('conn.php');
$nicheng=$_GET['zj'];
$nr=$_GET['nr'];
//2.执行sql
$sql_select = "select * from user where nicheng='$nicheng'";
$stmt = mysqli_query($conn,$sql_select);
//    var_dump($stmt);
//    die();
$user = mysqli_fetch_assoc($stmt); // 解析数据
?>


<h3>回复信息</h3>
<form   method="post" class="form-inline">

    <div class="form-group">
<span>给<?php echo $nicheng;?>回复</span>
<br>
<span>Ta说：<?php echo $nr;?></span>
         <input type="text" name="duiimg" class="form-control" style="display:none"  value="<?php echo $_SESSION['img'];?>">
       <input type="text" name="duif" class="form-control"  style="display:none" value="<?php echo $user['nicheng'];?>">
       <input type="text" name="ss" class="form-control" style="display:none" value="<?php echo $time = date('Y-m-d h:i:s', time());?>">
        <input type="text" name="zj" class="form-control" style="display:none"  value="<?php echo $_SESSION['nicheng'];?>">
        </span>
<input type="text" name="username" class="form-control" style="display:none"  value="<?php echo $user['username'];?>">
        </span>
<br><br>
<span class="font">内容:</span><textarea  name="nr" id="" class="form-control" cols="30" rows="10" placeholder="请输入>>>"></textarea>
        </span>
<br><br>
        <a href="main.php" class="btn btn-success">返回</a>
        <input type="submit" value="发送" class="btn btn-primary">
        <input type="reset" value="重置" class="btn btn-warning">
    </div>


</form>
<?php
if($_SERVER["REQUEST_METHOD"]=="POST") {
include('conn.php');
    $duif = $_POST['duif'];
    $ss = $_POST['ss'];
    $zj = $_POST['zj'];
    $nr = $_POST['nr'];
    $username = $_POST['username'];
$duiimg = $_POST['duiimg'];


 $sql = "select * from xiaoxi where duif= '{$_POST['duif']}' and nr='{$_POST['nr']}' and zj='{$_POST['zj']}'";
          
          $rs = mysqli_query($link, $sql); //执行sql查询
          $row = mysqli_fetch_assoc($rs);
       
          if ($row) { // 用户存在；
              if ($_POST['duif'] == $row['duif'] && $_POST['nr'] == $row['nr']&& $_POST['zj'] == $row['zj']) {
                echo  "<script>alert('请勿重复发送！');</script>";
              }
                
              }else{

             
    $sql = "insert into xiaoxi (duif, ss, zj, nr,username,duiimg) values ('$duif', '$ss','$zj','$nr','$username','$duiimg')";
    $rw = mysqli_query($conn, $sql);
    if ($rw) {
          
           echo "<script>alert('已发送！');window.open('wdx.php')</script>";
    } else {
        echo "<script>alert('发送失败');window.open('wdx.php')</script>";
    }
 header("refresh:0.5;url=wdx.php");
}
}

?>



</body>
</html>